using System;
using System.Collections;
using System.Collections.Generic;
using FlowCanvas;
using FlowCanvas.Nodes;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
using UnityEngine.Playables;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    [Category("Ggame")]
    public class ShowPowerUpAnim : LatentActionNodeBase
    {
        [RequiredField]
        public BBParameter<int> fromValue;

        public BBParameter<int> toValue;
        
        [HideInInspector] 
        public FlowOutput onComplete;
        
        private bool stopped = false;
        
        public IEnumerator Invoke()
        {
            stopped = false;
            BlueprintUtils.PlayPowerUpAnim(fromValue.value, toValue.value, OnCompleted);
            yield return new UnityEngine.WaitUntil(() =>
            {
                return stopped;
            });
        }
        
        private void OnCompleted(PlayableDirector director)
        {
            onComplete?.Call(new Flow());
            stopped = true;
        }

        protected override void OnRegisterDerivedPorts(FlowNode node)
        {
            onComplete = node.AddFlowOutput("onComplete");
            node.AddFlowInput("In", (f) => { Begin(Invoke(), f); });
        }
    }
    
}